﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace uk.org.aspellclark.todolistppc
{
    public partial class FrmPreferences : Form
    {
        PreferencesXml oPreferences;
        public FrmPreferences()
        {
            InitializeComponent();
            LoadControls();
        }
        private void LoadControls()
        {
            try
            {
                PreferencesXml oPreferences = new PreferencesXml();
                oPreferences.readFromFile();
                cmbFontSize.SelectedItem = oPreferences.getPreference("FontSize");
                chkButtonMenuEnabled.Checked = Convert.ToBoolean(oPreferences.getPreference("ButtonMenuEnabled"));
                chkUseXMLDOM.Checked = Convert.ToBoolean(oPreferences.getPreference("XMLDOM"));
            }
            catch
            {
                cmbFontSize.SelectedItem = 2;
                chkButtonMenuEnabled.Checked = false;
                chkUseXMLDOM.Checked = false;

            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cmbFontSize.SelectedItem != null)
            {
                SetPref("FontSize", cmbFontSize.SelectedItem.ToString());
            }
            SetPref("ButtonMenuEnabled", chkButtonMenuEnabled.Checked.ToString());
            SetPref("XMLDOM", chkUseXMLDOM.Checked.ToString());
            this.Close();
        }
        #region Private Methods
        private void SetPref(string psName, string psValue)
        {
            PreferencesXml oPreferences = new PreferencesXml();
            oPreferences.setPreference(psName, psValue);
            oPreferences.writeToFile();
        }
        private string GetPref(string psName)
        {
            oPreferences = new PreferencesXml();
            return oPreferences.getPreference(psName);
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}